草庐IT

Android JsonArray 和 JsonObject 反序列化

全部标签

c# - XML 反序列化 IEnumerable 类时出错

我正在尝试将HistoryRoot类序列化和反序列化为这种XML格式:这是HistoryRoot、HistoryList和HistoryItem类:[Serializable]publicclassHistoryRoot{publicHistoryListFiles=newHistoryList{sl=newSortedList(),list=newList(),max=500,c=program.M.qFile},Folders=newHistoryList{sl=newSortedList(),list=newList(),max=100,c=program.M.qFolder},

c# - 嵌套的 XML 序列化 C#

我需要创建带有序列化的嵌套Xml。我有两个列表,其中的数据必须生成按数字过滤的嵌套xml。列表:ListpersonList=newList();personList.Add(newPerson{Number=1,Name="Dean"});personList.Add(newPerson{Number=2,Name="Mike"});ListhomeList=newList();homeList.Add(newHome{Number=2,City="Paris",State="France"});homeList.Add(newHome{Number=1,City="London",

c# 使用 IXmlSerializable 反序列化

我有这样的xml:26,5016980000008,4142780000009,2926740000008,5519820000007,16460500000016,5016980000008,4142780000009,2926740000008,5519820000007,164605000000我需要将它反序列化为类。但问题是,那一周以后会改变(它将包含更多元素,我不知道它们的名称)数据:[XmlRoot("data")]publicclassData{[XmlArray("audit_values")][XmlArrayItem("audit_value",IsNullable

c# - 在 C# 中将 Xml 反序列化为对象

我有一些要序列化的XML。我的代码运行没有错误,但是序列化不成功,对象是空的而不是用数据填充。该值只是类型值:{OrangeCdToCollectorz.OrangeCd}。我怀疑我的类(class)定义。这也是我正在序列化的类:[Serializable,XmlRoot(ElementName="Collection")][XmlType("Collection")]publicclassOrangeCd{[XmlRoot(ElementName="Artists")]publicclassArtists{[XmlAttribute(AttributeName="Various")]

C# 序列化从结果中删除属性名称

我无法从我的xml中删除clsProduct中的属性Values的名称。我尝试使用[XmlElement(ElementName="Values",Type=typeof(clsValues)]对于我的List但它没有给我我需要的结果。你可以在下面看到我需要的结果。我的序列化类的一部分:[Serializable]publicclassclsProduct{[XmlAttribute("ID")]publicstringID{get;set;}[XmlAttribute("UserTypeID")]publicstringUserTypeID{get;set;}[XmlArrayIte

c# - 序列化在 c# 中实现 IEnumerable 的自定义泛型类型

我有一个通用类型Foo1,它基本上是一个包含一些元数据和通用列表的容器。当我序列化该类型时,它获得名称“Foo1Of”+TypeParameterName。publicclassFoo1{publicstringName{get;set;}=string.Empty;publicListList{get;set;}=newList();}[TestMethod]publicvoidSerializeFoo1(){Foo1foo=newFoo1{Name="Foo1",List={"Bar","Baz"}};XmlSerializers=newXmlSerializer(foo.GetT

c# - 仅反序列化 XML 中的特定项目并添加到列表

我有一个包含多个项目的XML文件,我想一次只反序列化一个特定的项目,而不是所有项目,然后将其添加到列表中。使用thissite中的示例,如何仅反序列化Id=2的Product并将其添加到productList?类:publicclassProduct{publicintId{get;set;}publicstringName{get;set;}}代码:voidfoo(){stringxmlString="1MyXMLproduct2Mysecondproduct";XmlSerializerserializer=newXmlSerializer(typeof(List),newXmlR

c# - 在 C# 中将 XML 空日期反序列化为 DateTime

我有以下XML需要反序列化为C#对象。除了有时为空的日期元素外,所有元素都有效。ModifiedDateSpecified模型类定义为:[System.Xml.Serialization.XmlType(Namespace="http://webservices.mycompany.com/Order/17.2.0",AnonymousType=true)][System.Xml.Serialization.XmlRoot(Namespace="http://webservices.mycompany.com/Order/17.2.0",IsNullable=false)]public

c# - 序列化 List<T> 的 XmlSerializer 的构造函数在与 XmlAttributeOverrides 一起使用时抛出 InvalidOperationException

总结使用XmlSerializer时类,序列化一个List(其中T可以用XmlSerializer毫无问题地序列化)使用XmlAttributeOverrides像这样:usingxmls=System.Xml.Serialization;...xmls.XmlAttributeOverridesattributeOverrides=newxmls.XmlAttributeOverrides();attributeOverrides.Add(typeof(T),newxmls.XmlAttributes(){XmlRoot=newxmls.XmlRootAttribute("foo")

c# - 如何使用 XML 阅读器反序列化 XML 片段

我正在尝试反序列化一个Xml片段。我快到了,但它抛出了一个错误,它不期望第一个元素。流中的XML示例如下:12009-03-16T20:34:57.022167+00:00222009-03-11T20:34:57.022167+00:00DescriptionherePojecttitle51234567我正在使用以下代码反序列化:XmlSerializerserializer=newXmlSerializer(typeof(Project));XmlReaderSettingssettings=newXmlReaderSettings();settings.ValidationFl